package com.yhl.person.services.imp;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yhl.person.bean.User;
import com.yhl.person.dao.UserDao;
import com.yhl.person.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author HelenYang
 * @since 2022-03-20
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {
    @Autowired UserDao userDao;

    public List<User> getUsers(){
        return userDao.selectList(Wrappers.<User>lambdaQuery().eq(User::getOpt, 0));
    }
    public int updateUsers(User user){
        return userDao.updateById(user);
    }
    public User getUserByName(String name){
        return userDao.selectOne(Wrappers.<User>lambdaQuery().eq(User::getName, name).eq(User::getOpt, 0));
    }
    public User getUserById(String id){
        return userDao.selectOne(Wrappers.<User>lambdaQuery().eq(User::getId, id));
    }
    /**
     * 增加用户
     * @param user
     * @return
     */
    public int addUser(User user){
        int insert = userDao.insert(user);
        if (insert >= 1){
            return 1;
        }else{
            return 0;
        }
    }
    public int addUserList(){
        List<User> list = new ArrayList<>();
        list.add(new User());

        for (int i = 0; i < 100; i++) {
            User user = new User();

            user.setAge(20);
        }
        return 0;
    }
}
